<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout}">

<head>
    <title layout:title-pattern="$LAYOUT_TITLE - $CONTENT_TITLE"
           th:text="${drug.id != null} ? '编辑药品' : '新增药品'"></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body class="bg-light">
<div layout:fragment="content">
    <div class="card">
        <div class="card-header">
            <h2 th:text="${drug.id != null} ? '编辑药品信息' : '添加新药品'"></h2>
        </div>
        <div class="card-body">
            <form th:action="@{/api/drugs/save}" th:object="${drug}" method="post">
                <input type="hidden" th:field="*{id}"/>

                <div class="mb-3">
                    <label class="form-label">药品名称</label>
                    <input type="text" class="form-control" th:field="*{name}" required>
                </div>

                <div class="mb-3">
                    <label class="form-label">生产厂商</label>
                    <input type="text" class="form-control" th:field="*{manufacturer}">
                </div>

                <div class="row mb-3">
                    <div class="col-md-6">
                        <label class="form-label">价格</label>
                        <input type="number" step="0.01" class="form-control" th:field="*{price}" required>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">库存数量</label>
                        <input type="number" class="form-control" th:field="*{stock}" required>
                    </div>
                </div>

                <div class="mb-3">
                    <label class="form-label">规格说明</label>
                    <textarea class="form-control" th:field="*{specification}" rows="3"></textarea>
                </div>
                <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
            <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                <form th:action="@{/api/drugs}" method="get">
                    <button type="submit" class="btn btn-outline-secondary">取消</button>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>